/**
 * 删除
 * @param lableId datagrid
 * @param alertStr 确认删除提示信息
 * @param url 网络接口
 */
function lananDelete(lableId, alertStr, url) {
    var select = $('#' + lableId).datagrid('getSelected');
    if (select == null) {
        $.messager.alert("提示","请选择要删除的项！","info");
        return;
    }
    $.messager.confirm("确认",alertStr, function(yes){
        if(yes){
            $.messager.progress();
            $.ajax({
                url:url,
                type:"post",
                data:{id : select.id, openid : select.openid},
                dataType:"json",
                success:function(data){
                    $.messager.progress("close");
                    if(data.success){
                        $.messager.show({
                            title:"删除成功",
                            msg:"删除成功!",
                            timeout:600,
                            style:"left:30%;top:10%",
                            showType:"fade"
                        });
                        $("#" + lableId).datagrid('clearSelections');
                        $("#" + lableId).datagrid("reload");
                    }else{
                        $.messager.alert("删除失败", data.msg,"error");
                    }
                },
                error:function(){
                    $.messager.progress("close");
                    $.messager.alert("删除失败", "服务器连接失败!","error");
                }
            });
        }
    });
}

function lananUpdateOrInsert(msg, url, formId, closeId, reloadId) {
    $.messager.progress();
    $("#" + formId).form("submit",{
        url:url,
        onSubmit:function(){
            var valid = $(this).form("validate");
            if (!valid) {
                $.messager.progress("close");
            }
            return valid;
        },
        success:function(data){
            data=$.parseJSON(data);
            $.messager.progress("close");
            if(data.success){
                $("#" + closeId).dialog("close");
                $.messager.show({
                    title: msg + "成功",msg: msg + "成功!",
                    timeout:600,style:"left:30%;top:10%",
                    showType:"fade"
                });
                $("#" + reloadId).datagrid("reload");
                // $('#' + reloadId).datagrid('clearSelections');
            }else{
                $.messager.alert(msg + "失败", data.msg,"error");
            }
        },
        error:function () {
            $.messager.progress("close");
            $.messager.alert("操作失败", "服务器连接失败!","error");
        }
    });
}


/****
 * //扩展的Date的format方法(上述插件实现) 日期转换格式
 *@author Edward_yang
 * @uptime 2017-12-15
 * @param format
 * @returns {*}
 */
Date.prototype.format = function (format) {
    var o = {
        "M+": this.getMonth() + 1, // month
        "d+": this.getDate(), // day
        "h+": this.getHours(), // hour
        "m+": this.getMinutes(), // minute
        "s+": this.getSeconds(), // second
        "q+": Math.floor((this.getMonth() + 3) / 3), // quarter
        "S": this.getMilliseconds()
        // millisecond
    }
    if (/(y+)/.test(format))
        format = format.replace(RegExp.$1, (this.getFullYear() + "")
            .substr(4 - RegExp.$1.length));
    for (var k in o)
        if (new RegExp("(" + k + ")").test(format))
            format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));
    return format;
}
/***
 * //调用日期转化格式方法
 * @author Edward_yang
 * @uptime 2017-12-15
 * @param value
 * @returns {*}
 */
function formatDatebox(value) {

    if (value == null || value == '') {
        return '';
    }
    var dt;
    if (value instanceof Date) {
        dt = value;
    } else {
        dt = new Date(value);
    }

    return dt.format("yyyy-MM-dd hh:mm:ss");
}
function formatDateboxYMD(value,formatStr) {

    if (value == null || value == '') {
        return '';
    }
    var dt;
    if (value instanceof Date) {
        dt = value;
    } else {
        dt = new Date(value);
    }

    return dt.format(formatStr);
}


/**
 * 日期验证 Lanan
 * @param date 待验证日期
 * @param msg 提示语
 * @returns {boolean} ture:是日期
 */
function checkDate(date, msg){
    var a = /^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2})$/;
    var result = date.match(a);
    if (result == null) {
        $.messager.alert("提示", msg, "info");
        return false
    }
    else
        return true
}

function formatDate(date, format) {
    if (!date) return;
    if (!format) format = "yyyy-MM-dd";
    switch(typeof date) {
        case "string":
            date = new Date(date.replace(/-/, "/"));
            break;
        case "number":
            date = new Date(date);
            break;
    }
    if (!date instanceof Date) return;
    var dict = {
        "yyyy": date.getFullYear(),
        "M": date.getMonth() + 1,
        "d": date.getDate(),
        "H": date.getHours(),
        "m": date.getMinutes(),
        "s": date.getSeconds(),
        "MM": ("" + (date.getMonth() + 101)).substr(1),
        "dd": ("" + (date.getDate() + 100)).substr(1),
        "HH": ("" + (date.getHours() + 100)).substr(1),
        "mm": ("" + (date.getMinutes() + 100)).substr(1),
        "ss": ("" + (date.getSeconds() + 100)).substr(1)
    };
    return format.replace(/(yyyy|MM?|dd?|HH?|ss?|mm?)/g, function() {
        return dict[arguments[0]];
    });
}

function formatterMoneyType(value) {
    if(value == "0") {
        return  '<span style="color:green">' + '充值' + '</span>';
    } else if(value == "1") {
        return  '<span style="color:#f93">' + '扣款' + '</span>';
    } else if (value == "2") {
        return  '<span style="color:greenyellow">' + '提现' + '</span>';
    }  else if (value == "3") {
        return  '<span style="color:blueviolet">' + '删除' + '</span>';
    } else if (value == "4") {
        return  '<span style="color:indianred">' + '支付宝支付' + '</span>';
    } else if (value == "5") {
        return  '<span style="color:orangered">' + '微信支付' + '</span>';
    } else if (value == "6") {
        return  '<span style="color:red">' + '余额支付' + '</span>';
    }
}